package com.ie.service.before;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.common.http.ResponseResult;
import com.ie.entity.FocusEntity;
import com.ie.mapper.before.FocusMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class FocusServiceImpl extends ServiceImpl<FocusMapper, FocusEntity> implements FocusService {
    @Override
    public ResponseResult<Map<String, Object>> addFocus(FocusEntity focusEntity) {
        Long n = query()
                .eq("busertable_id", focusEntity.getBusertableId())
                .eq("goodstable_id", focusEntity.getGoodstableId())
                .count();
        if (n > 0) {//该商品已关注
            return ResponseResult.getMessageResult(null, "A001");
        }
        focusEntity.setFocustime(new Date());
        boolean flag = save(focusEntity);
        if (flag) {
            return ResponseResult.getMessageResult(null, "A002");
        }
        return ResponseResult.getMessageResult(null, "A003");
    }
}
